﻿using AutoMapper;
using B.S.NewMedical.Api.Read.DTOS.Carousel;
using B.S.NewMedical.Api.Read.DTOS.Department;
using B.S.NewMedical.Api.Read.DTOS.Hospital;
using B.S.NewMedical.Domain.Hospital;
using B.S.NewMedical.Domain.Doctor;
using B.S.NewMedical.Api.Read.DTOS.Doctor;
using B.S.NewMedical.Api.Read.DTOS.Consult;
using B.S.NewMedical.Api.Read.DTOS.Guide;
using B.S.NewMedical.Api.Read.DTOS.Price;
using B.S.NewMedical.Domain.Appointment;
using B.S.NewMedical.Domain.MobileService;
using B.S.NewMedical.Api.Read.DTOS.Patient;
using B.S.NewMedical.Api.Read.DTOS.VisitRecord;
using B.S.NewMedical.Api.Read.DTOS.Drug;
using B.S.NewMedical.Api.Read.DTOS.Checkup;
using B.S.NewMedical.Api.Read.DTOS.Test;

namespace B.S.NewMedical.Api.Read
{
    public class MapperProfiles : Profile
    {
        public MapperProfiles()
        {
            // 轮播图映射配置
            CreateMap<CarouselModel, CarouselDto>();

            //患者 
            CreateMap<PatientModel, PatientDisplayDto>().ReverseMap();

            //就诊记录
            CreateMap<VisitRecordModel, VisitRecordDto>();

            // 科室映射配置
            CreateMap<DepartmentModel, DepartmentDto>();
            
            // 科室显示DTO映射配置
            CreateMap<DepartmentModel, DepartmentDisplayDto>()
                .ForMember(dest => dest.Level, opt => opt.Ignore()) // 级别在Handler中手动设置
                .ForMember(dest => dest.ParentDepartmentName, opt => opt.Ignore()); // 父级科室名称在Handler中手动设置
            
            // 医院映射配置
            CreateMap<HospitalModel, HospitalDto>()
                .ForMember(dest => dest.DepartmentSetup, opt => opt.Ignore()) // 科室信息将在Handler中单独处理
                .ForMember(dest => dest.HospitalTypeName, opt => opt.Ignore()); // 医院类型名称在Handler中手动设置
            
            // 医院类型映射配置
            CreateMap<HospitalTypeModel, HospitalTypeDto>();
            
            // 开单申请表映射
            CreateMap<PrescriptionApplicationModel, PrescriptionApplicationDto>();

            // 开单申请明细映射
            CreateMap<PrescriptionDetailModel, PrescriptionDetailDto>();
            
            // 药品类型映射
            CreateMap<DrugCategoryModel, DrugCategoryDto>();
            
            // 检查项目分类映射
            CreateMap<CheckupCategoryModel, CheckupCategoryDto>();
            
            // 检验项目分类映射
            CreateMap<TestCategoryModel, TestCategoryDto>();
            
            // 健康咨询分类映射
            CreateMap<ConsultCategory, ConsultCategoryDto>();

            // 健康咨询问题映射
            CreateMap<ConsultQuestion, ConsultQuestionDto>()
                .ForMember(dest => dest.CategoryName, opt => opt.Ignore());

            // 健康咨询回答映射
            CreateMap<ConsultAnswer, ConsultAnswerDto>()
                .ForMember(dest => dest.DoctorName, opt => opt.Ignore())
                .ForMember(dest => dest.DoctorTitle, opt => opt.Ignore())
                .ForMember(dest => dest.Department, opt => opt.Ignore())
                .ForMember(dest => dest.Hospital, opt => opt.Ignore())
                .ForMember(dest => dest.Avatar, opt => opt.Ignore());
                
            // 医生映射
            CreateMap<Domain.Appointment.Doctor, DoctorDto>()
                .ForMember(dest => dest.DoctorCode, opt => opt.MapFrom(src => src.Doctor_code))
                .ForMember(dest => dest.DoctorName, opt => opt.MapFrom(src => src.Doctor_name))
                .ForMember(dest => dest.DeptId, opt => opt.MapFrom(src => src.Dept_id))
                .ForMember(dest => dest.JobTitleId, opt => opt.MapFrom(src => src.JobTitle_id))
                .ForMember(dest => dest.DepartmentName, opt => opt.Ignore())
                .ForMember(dest => dest.JobTitleName, opt => opt.Ignore())
                .ForMember(dest => dest.HospitalId, opt => opt.Ignore())
                .ForMember(dest => dest.HospitalName, opt => opt.Ignore());
                
            // 价格服务类型映射
            CreateMap<PriceServiceType, PriceServiceTypeDto>()
                .ForMember(dest => dest.DeptName, opt => opt.Ignore());
                
            // 价格条目映射
            CreateMap<PriceItem, PriceItemDto>()
                .ForMember(dest => dest.TypeName, opt => opt.Ignore())
                .ForMember(dest => dest.CategoryTag, opt => opt.Ignore());
                
            // 就医指南分类映射
            CreateMap<GuideCategory, GuideCategoryDto>();
                
            // 就医指南文章映射
            CreateMap<GuideArticle, GuideArticleDto>()
                .ForMember(dest => dest.CategoryName, opt => opt.Ignore());
        }
    }
}
